package com.example.shorg.dto;

import com.example.shorg.dataobject.OrderDetail;
import com.example.shorg.dataobject.OrderMaster;
import com.example.shorg.enums.OrderStatusEnum;
import com.example.shorg.enums.PayStatusEnum;
import com.example.shorg.utils.EnumStatusUtils;
import com.example.shorg.utils.serializer.Date2LongSerializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.Id;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
//做到空的时候不返回该字段
//@JsonInclude(JsonInclude.Include.NON_NULL)
@Slf4j
public class OrderDTO {
    /**订单id**/
    @Id
    private String orderId;

    /**订单名称*/
    private String buyerName;

    /**订单手机号码*/
    private String buyerPhone;

    /**订单地址*/
    private String buyerAddress;

    /**微信的openid*/
    private String buyerOpenid;

    /**订单价格*/
    private BigDecimal orderAmount;

    /**订单状态 0新的订单，1已完成， 2已取消*/
    private Integer orderStatus ;

    /**订单的支付状态  0等待完成*/
    private Integer payStatus ;

    /**订单的创建时间*/
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date createTime;

    /**更新时间*/
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date updateTime;

    private List<OrderDetail> orderDetailList = new ArrayList<>();

    /**订单状态转换*/
    @JsonIgnore
    public OrderStatusEnum getOrderStatusEnum(){
        OrderStatusEnum byCode = EnumStatusUtils.getByCode(orderStatus, OrderStatusEnum.class);
        if(byCode == null){
            log.error("错误的是空的");
            return null;
        }
        log.error("123", byCode.getMsg());
        return byCode;
    }

    /**支付状态装换*/
    @JsonIgnore
    public PayStatusEnum getPayStatusEnum(){
        return EnumStatusUtils.getByCode(payStatus, PayStatusEnum.class);
    }
}
